
package bankservice.endpoint;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import javax.xml.ws.Endpoint;

public class BankPublisher{

	public BankPublisher() {
   	}
	
	public static void main(String args[]) {
		
		String branchCode;
		      	
      	try{      		
      		
      		 InputStreamReader is = new InputStreamReader(System.in);
             BufferedReader br = new BufferedReader(is);

		     System.out.println("Please Enter the Branch Code:");

		     branchCode = br.readLine();	    	  
		    
		     // create a bank object 
		      
		     BankImpl bank = new BankImpl();
		      
		     bank.setBranchCode(branchCode);
		     bank.initializeBank();
      		      		
		     // Publish the bank object on the web
		     		     
		     if (branchCode.equals("01")){
		    	 
		    	 ServerListener serverListener = new ServerListener(bank,6000);
		    	 serverListener.start();
		    	 
		    	 Endpoint.publish("http://127.0.0.1:9876/endpoint",bank);
		    	 
		     }else if (branchCode.equals("02")){
		    	 
		    	  ServerListener serverListener = new ServerListener(bank,6500);
		    	  serverListener.start();
		    	 
		    	  Endpoint.publish("http://127.0.0.1:9877/endpoint",bank);		    	 
		     }      		     
      		 
      		 System.out.println("Bank Server of Bank Branch " + branchCode + " starts running!");		    
      	}     	
      	catch (Exception re) {
         	System.out.println("Exception in BankPublisher.main: " + re);         	
    	} 
	} 
   	
}//end class
